// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   iDBManager2000.java

package DBstep;

import java.io.PrintStream;
import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class iDBManager2000
{

    public String ClassString;
    public String ConnectionString;
    public String UserName;
    public String PassWord;
    public Connection Conn;
    public Statement Stmt;

    public iDBManager2000()
    {
        ClassString = null;
        ConnectionString = null;
        UserName = null;
        PassWord = null;
    }

    public boolean OpenConnection()
    {
        boolean mResult = true;
        try
        {
            Class.forName(ClassString);
            if(UserName == null && PassWord == null)
                Conn = DriverManager.getConnection(ConnectionString);
            else
                Conn = DriverManager.getConnection(ConnectionString, UserName, PassWord);
            Stmt = Conn.createStatement();
            mResult = true;
        }
        catch(Exception e)
        {
            System.out.println(e.toString());
            mResult = false;
        }
        return mResult;
    }

    public void CloseConnection()
    {
        try
        {
            Stmt.close();
            Conn.close();
        }
        catch(Exception e)
        {
            System.out.println(e.toString());
        }
    }

    public static String GetDateTime()
    {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String mDateTime = formatter.format(cal.getTime());
        return mDateTime;
    }

    public static Date GetDate()
    {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String mDateTime = formatter.format(cal.getTime());
        return Date.valueOf(mDateTime);
    }

    public int GetMaxID(String vTableName, String vFieldName)
    {
        int mResult = 0;
        boolean mConn = true;
        String mSql = new String();
        mSql = String.valueOf(String.valueOf((new StringBuffer("select max(")).append(vFieldName).append(")+1 as MaxID from ").append(vTableName)));
        try
        {
            if(Conn != null)
                mConn = Conn.isClosed();
            if(mConn)
                OpenConnection();
            ResultSet result = ExecuteQuery(mSql);
            if(result.next())
                mResult = result.getInt("MaxID");
            result.close();
            if(mConn)
                CloseConnection();
        }
        catch(Exception e)
        {
            System.out.println(e.toString());
        }
        return mResult;
    }

    public ResultSet ExecuteQuery(String SqlString)
    {
        ResultSet result = null;
        try
        {
            result = Stmt.executeQuery(SqlString);
        }
        catch(Exception e)
        {
            System.out.println(e.toString());
        }
        return result;
    }

    public int ExecuteUpdate(String SqlString)
    {
        int result = 0;
        try
        {
            result = Stmt.executeUpdate(SqlString);
        }
        catch(Exception e)
        {
            System.out.println(e.toString());
        }
        return result;
    }
}
